package cn.com.css.taxInspection.workflow.controller;

import java.text.ParseException;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.gt3.entity.SyJcKhfmxEntity;
import cn.com.css.taxInspection.gt3.service.SyJcKhfmxService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.entity.WorkflowVisitEntity;
import cn.com.css.taxInspection.workflow.service.WorkflowVisitService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

@Controller
@RequestMapping("/workflow/visit")
public class WorkflowVisitController {

    @Resource
    private SyJcKhfmxService syJcKhfmxService;
    @Resource
    private WorkflowVisitService workflowVisitService;
    @Resource
    private HttpSessionService httpSessionService;

    @ApiOperation(value = "案件回访-待回访列表")
    @PostMapping("/list")
    @ResponseBody
    public DataResult list(@RequestBody SyJcKhfmxEntity syJcKhfmxEntity) throws ParseException {
        IPage<SyJcKhfmxEntity> iPage = syJcKhfmxService.infopage(syJcKhfmxEntity);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "案件台账-已回访列表")
    @PostMapping("/list1")
    @ResponseBody
    public DataResult listBylog(@RequestBody SyJcKhfmxEntity syJcKhfmxEntity) throws ParseException {
        IPage<SyJcKhfmxEntity> iPage = syJcKhfmxService.infopage1(syJcKhfmxEntity);
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "案件台账-回访")
    @PostMapping("/visit")

    @ResponseBody
    public DataResult visit(@RequestBody SyJcKhfmxEntity syJcKhfmxEntity) throws ParseException {
        String currentUserId = httpSessionService.getCurrentUserId();
        String currentDeptId = httpSessionService.getCurrentDeptId();
        String bz = syJcKhfmxEntity.getBz();
        if (TsBqUtils.isNull(bz)) {
            return DataResult.fail("bz不能为NULL");
        }
        String jcajxxuuid = syJcKhfmxEntity.getJcajxxuuid();
        if (TsBqUtils.isNull(jcajxxuuid)) {
            return DataResult.fail("jcajxxuuid不能为NULL");
        }
        syJcKhfmxService.visit(syJcKhfmxEntity);
        WorkflowVisitEntity workflowVisitEntity = new WorkflowVisitEntity();
        workflowVisitEntity.setId(TsBqUtils.getUUID());
        workflowVisitEntity.setRelevance(jcajxxuuid);
        workflowVisitEntity.setVisitMan(currentUserId);
        workflowVisitEntity.setVisitContent(bz);
        workflowVisitEntity.setTaxorgcode(currentDeptId);
        workflowVisitEntity.setDeleted(Constants.DATA_NOT_DELETED);
        workflowVisitEntity.setCreateTime(new Date());
        workflowVisitEntity.setCreateId(currentUserId);
        workflowVisitService.save(workflowVisitEntity);
        return DataResult.success();
    }
}
